package carltechnology.com.mahjonggame.utils.dao.impl;

import carltechnology.com.mahjonggame.mode.IData;
import carltechnology.com.mahjonggame.utils.dao.IMahjongDataBaseManager;
import carltechnology.com.mahjonggame.utils.dao.IMahjongSource;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;

/**
 * Created by WZTCM on 2016/6/1.
 */
public class MahjongDatabaseManager implements IMahjongDataBaseManager {
    private static IMahjongDataBaseManager instance;
    private Observable<IData> mahjongGameObservable;
    private MahjongGameInfoStoreHelper mahjongGameInfoStoreHelper;
    private Observable<IData> mahjongGameInfoDetailObservable;
    private IMahjongSource dataSource;
    private MahjongDatabaseManager() {
        dataSource = new DatabaseSource();
        mahjongGameObservable = dataSource
                .getMahjongGameInfoSource();
        mahjongGameInfoStoreHelper = dataSource
                .getMahjongGameInfoStoreHelper();
    }

    @Override
    public Subscription getMahjongGameInfo(Subscriber<IData> subs) {
        return mahjongGameObservable.subscribe(subs);
    }

    @Override
    public Subscription getMahjongGameDetailInfo(Subscriber<IData> subs, final int id) {
        mahjongGameInfoDetailObservable = dataSource.getMahjongGameDetailAllInfoSource(id);
        return mahjongGameInfoDetailObservable.subscribe(subs);
    }

    @Override
    public void storeMahjongGameInfo(IData data) {
        mahjongGameInfoStoreHelper.storeMahjongInfo(data);
    }

    @Override
    public void endStoreMahjongGameInfo() {
        mahjongGameInfoStoreHelper.endStore();
    }

    @Override
    public void beginStoreMahjongGameInfo() {
        mahjongGameInfoStoreHelper.beginStore();
    }

    public static IMahjongDataBaseManager getInstance(){
        if (instance==null){
            instance = new MahjongDatabaseManager();
        }
        return instance;
    }



}
